home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / text / dtp / txtRotator303.lha / txtRotator303.rexx < prev   
OS/2 REXX Batch file  |  1996-09-25  |  10KB  |  347 lines

  1. /*--------------------------------------*/
  2. /* $VER: txtRotator V3.03 (25 Sep 1996) */
  3. /* ©1996 Michael Merkel                 */
  4. /*--------------------------------------*/
  5.  
  6. /*
  7.    how to use this:
  8.    ----------------
  9.  
  10.    1. draw a circle/ellipse/arc/pie with PageStream3
  11.       (please use PageStream3.1 BETA 3 or higher with this script
  12.        due to problems with rotated text objects in earlier versions)
  13.    2. select this object
  14.    3. start this script
  15.    4. press OK to see what happens
  16.  
  17.    notes:
  18.    ------
  19.  
  20.    * this script does NOT work with rotated objects!
  21.      (do it with the unrotated object first then group it and rotate all)
  22.    * it only works with "normal" circles/ellipses/arcs/pies
  23.    * text around ellipses sometimes look wierd - play with it
  24.  
  25.    comments to this program to:
  26.    ----------------------------
  27.       mmerkel@rummelplatz.uni-mannheim.de
  28.  
  29.    this is my first public arexx-script... don't blame me for that :-)
  30.  
  31.    IF YOU LIKE THIS SCRIPT PLEASE SEND ME A HARDCOPY OF THE
  32.    PAGESTREAM SCREEN WITH YOUR WORK ON IT!
  33.  
  34.    happy rotating...
  35.  
  36.    Michael Merkel
  37. */
  38.  
  39.  
  40. OPTIONS RESULTS
  41.  
  42. /* Make sure rexx support is opened */
  43. IF ~SHOW('L','rexxsupport.library') THEN
  44.    CALL ADDLIB('rexxsupport.library',0,-30)
  45. IF ~SHOW('L','softlogik:libs/slarexxsupport.library') THEN
  46.    CALL ADDLIB('softlogik:libs/slarexxsupport.library',0,-30)
  47. IF ~SHOW('L','rexxmathlib.library') THEN
  48.    CALL ADDLIB('rexxmathlib.library',0,-30)
  49. ADDRESS 'PAGESTREAM'
  50.  
  51. 'GETOBJECT TYPE 'typ
  52.  ret = RESULT
  53. if (typ ~= 7) | (ret = 10) then call DOERRORREQUESTER
  54.  
  55. 'getellipse position koordinaten angles winkel'
  56. id = result
  57.  
  58. typ = winkel.type
  59.  
  60. startw = 0
  61. endw = 360
  62. if winkel.type ~= 'ELLIPSE' then do
  63.     endw = (450 - p2d(winkel.begin)) // 360
  64.     startw = (450 - p2d(winkel.end)) // 360
  65.     if endw < startw then endw = endw + 360
  66. end
  67.  
  68. call ReadTXTRotatorPrefs
  69.  
  70. measure = 'pt'
  71. posifaktor = 1
  72. rifaktor = 1
  73.  
  74. mx = p2d(koordinaten.centerx,measure)
  75. my = p2d(koordinaten.centery,measure)
  76. rx = p2d(koordinaten.radiusx,measure)
  77. ry = p2d(koordinaten.radiusy,measure)
  78.  
  79. call DOREQUESTER
  80. if ergebnis = cancelhandler THEN EXIT
  81.  
  82. call WriteTXTRotatorPrefs
  83.  
  84. size = textsize
  85. r    = radius
  86. mx = mx
  87. my = my
  88. rx = rx
  89. ry = ry
  90.  
  91. /* ---------------------------------------------------------------- */
  92.  
  93. 'REFRESH OFF'
  94.  
  95. 'OPENBUSYREQUESTER MESSAGE "text is placed around 'typ'..." THERMOMETER ENABLED ABORT ENABLED TOTAL 'l' CURRENT 0'
  96. BusyReq=result
  97.  
  98. highwinkel = -3.1415 * 0.5 + endw*3.1415/180
  99. lowwinkel  = -3.1415 * 0.5 + startw*3.1415/180
  100.  
  101. altrx = rx
  102. altry = ry
  103.  
  104. deltaradiusx = rx - (rx*icf)
  105. deltaradiusy = ry - (ry*icf)
  106.  
  107. deltaradiusrundx = deltaradiusx / xfaktor
  108. deltaradiusrundy = deltaradiusy / xfaktor
  109.  
  110. deltabuchstaben = l / xfaktor
  111.  
  112. deltaminusx = deltaradiusrundx / deltabuchstaben
  113. deltaminusy = deltaradiusrundy / deltabuchstaben
  114.  
  115. do num = 0 to l-1
  116.     call setbusy(num)
  117.  
  118.     'DRAWTEXTOBJ 'mx''measure' 'my''measure' INFRONT'
  119.      textid = RESULT
  120.     'SELECTTEXT AT 'mx''measure' 'my''measure' FRONTMOST'
  121.     'SETTYPESIZE 'size
  122.     'SETPARAGRAPHSTYLE 'charstyle
  123.     'INSERT "'SUBSTR(text,num+1,1)'"'
  124.     'GETTEXTOBJ POSITION txtpos2 OBJECTID 'textid
  125.  
  126.     if icf ~= 1 then call SCALEOBJECT(textid,(rx/altrx))
  127.  
  128.     txtheight = p2d(txtpos2.bottom,measure) - p2d(txtpos2.top,measure)
  129.     txtwidth  = p2d(txtpos2.right,measure)  - p2d(txtpos2.left,measure)
  130.  
  131.     sinus = (highwinkel-lowwinkel) / (l-1) * num + lowwinkel
  132.     dreh = sinus * 180 / 3.1415
  133.  
  134.     sinusresult   = sin(sinus)
  135.     cosinusresult = cos(sinus)
  136.  
  137.     nrx = rx + (txtheight/2)*posifaktor
  138.     nry = ry + (txtheight/2)*posifaktor
  139.  
  140.     xx2 = mx + cosinusresult * nrx
  141.     yy2 = my + sinusresult   * nry
  142.  
  143.     movx = (xx2-mx-(txtwidth/2))
  144.     movy = (yy2-my-(txtheight/2))
  145.  
  146.     'MOVE OFFSET 'movx''measure' 'movy''measure' OBJECTID 'textid
  147.  
  148.     /* Berechnen des Buchstaben-Drehwinkels */
  149.  
  150.     x0 = cosinusresult * rx
  151.     y0 = sinusresult   * ry
  152.  
  153.     if y0 = 0 then
  154.         dreh = -3.1415 / 2
  155.     else do
  156.         dreh = (x0*ry*ry)/(y0*rx*rx)
  157.         dreh = atan(dreh)
  158.     end
  159.     dreh = 180 + dreh * 180 / 3.1415
  160.  
  161.     if (y0 * rifaktor) > 0 then
  162.         'ROTATE 'dreh'°'
  163.     else
  164.         'ROTATE '180+dreh'°'
  165.  
  166.     if SUBSTR(text,num+1,1)==' ' then 'DELETEOBJECT objectid 'textid
  167.  
  168.     rx = rx - deltaminusx
  169.     ry = ry - deltaminusy
  170. end
  171.  
  172. call CLEANUP(1)
  173.  
  174. DOREQUESTER:
  175.     'ALLOCAREXXREQUESTER "text around 'typ' V3.02 ©1996 Michael Merkel" 320 200'
  176.      reqhandle = RESULT
  177.     'ADDAREXXGADGET 'reqhandle' EXIT 10  180 70 LABEL "_Ok"'
  178.      okhandler = RESULT
  179.     'ADDAREXXGADGET 'reqhandle' EXIT 240 180 70 LABEL "_Cancel"'
  180.      cancelhandler = RESULT
  181.  
  182.     'ADDAREXXGADGET 'reqhandle' STRING 150 10 50 STRING "'startw'" LABEL "angles (°) start:"'
  183.      start_gadget = RESULT
  184.     'ADDAREXXGADGET 'reqhandle' STRING 250 10 50 STRING "'endw'" LABEL "end:"'
  185.      end_gadget = RESULT
  186.     'ADDAREXXGADGET 'reqhandle' STRING 86 30 50 STRING "'textsize'" LABEL "fontsize:"'
  187.      s_gadget = RESULT
  188.     'ADDAREXXGADGET 'reqhandle' STRING 200 30 115 STRING "'charstyle'" LABEL "style:"'
  189.      style_gadget = RESULT
  190.     'ADDAREXXGADGET 'reqhandle' STRING 10 60 305 STRING "'text'" LABEL "text to be placed:" LABELPOS "ABOVELEFT"'
  191.      t_gadget = RESULT
  192.  
  193.     'ALLOCAREXXLIST'
  194.      rexxlist = RESULT
  195.     'ADDAREXXLIST 'rexxlist' "above line"'
  196.     'ADDAREXXLIST 'rexxlist' "below line"'
  197.     'ADDAREXXLIST 'rexxlist' "on line"'
  198.     'ADDAREXXGADGET 'reqhandle' CYCLE 94 90 120 LABEL "place text"'
  199.      c_gadget = RESULT
  200.     'SETAREXXGADGET 'reqhandle' 'c_gadget' LIST 'rexxlist' CURRENT 'tposi
  201.  
  202.     'ALLOCAREXXLIST'
  203.      rexxlist2 = RESULT
  204.     'ADDAREXXLIST 'rexxlist2' "clockwise"'
  205.     'ADDAREXXLIST 'rexxlist2' "counterclockwise"'
  206.     'ADDAREXXGADGET 'reqhandle' CYCLE 46 110 168 LABEL "text"'
  207.      ri_gadget = RESULT
  208.     'SETAREXXGADGET 'reqhandle' 'ri_gadget' LIST 'rexxlist2' CURRENT 'richtung
  209.  
  210.     'ADDAREXXGADGET 'reqhandle' STRING 174 130 40 STRING "'icf'" LABEL "inner circle factor:"'
  211.      icf_gadget = RESULT
  212.  
  213.     'ADDAREXXGADGET 'reqhandle' STRING 126 145 40 STRING "'xfaktor'" LABEL "surrounding #:"'
  214.      xfaktor_gadget = RESULT
  215.  
  216.     'DOAREXXREQUESTER 'reqhandle
  217.      ergebnis = RESULT
  218.  
  219.     'GETAREXXGADGET 'reqhandle' 'start_gadget' STRING'
  220.      startw = RESULT
  221.     'GETAREXXGADGET 'reqhandle' 'end_gadget' STRING'
  222.      endw = RESULT
  223.     'GETAREXXGADGET 'reqhandle' 's_gadget' STRING'
  224.      textsize = RESULT
  225.     'GETAREXXGADGET 'reqhandle' 'style_gadget' STRING'
  226.      charstyle = RESULT
  227.     'GETAREXXGADGET 'reqhandle' 't_gadget' STRING'
  228.      text = RESULT
  229.      l = length(text)
  230.     'GETAREXXGADGET 'reqhandle' 'c_gadget' CURRENT'
  231.      tposi = RESULT
  232.     'GETAREXXGADGET 'reqhandle' 'ri_gadget' CURRENT'
  233.      richtung = RESULT
  234.     'GETAREXXGADGET 'reqhandle' 'icf_gadget' STRING'
  235.      icf = RESULT
  236.     'GETAREXXGADGET 'reqhandle' 'xfaktor_gadget' STRING'
  237.      xfaktor = RESULT
  238.  
  239.     if tposi=1 then posifaktor = -1
  240.     if tposi=2 then posifaktor = 0
  241.  
  242.     endw = endw + 360*(xfaktor-1)
  243.  
  244.     if richtung = 1 then do
  245.         rifaktor = -1
  246.         dummy = startw
  247.         startw = endw
  248.         endw = dummy
  249.     end
  250.  
  251.     'FREEAREXXREQUESTER 'reqhandle
  252.     'FREAREXXLIST 'rexxlist
  253.     'FREAREXXLIST 'rexxlist2
  254. RETURN
  255.  
  256. DOERRORREQUESTER:
  257.     say 'Error: No circle/ellipse/arc/pie selected!'
  258.  
  259.     'ALLOCAREXXREQUESTER "Error!" 400 70'
  260.      reqhandle = RESULT
  261.     'ADDAREXXGADGET 'reqhandle' EXIT 165 50 70 LABEL "_Ok"'
  262.      dummy = RESULT
  263.  
  264.     'ADDAREXXGADGET 'reqhandle' TEXT 10 10 390 STRING "You did not chose an arc/ellipse/circle/pie!"'
  265.     'ADDAREXXGADGET 'reqhandle' TEXT 10 30 390 STRING "Select one and start me again!"'
  266.  
  267.     'DOAREXXREQUESTER 'reqhandle
  268.      dummy = RESULT
  269.  
  270.     'FREEAREXXREQUESTER 'reqhandle
  271.     exit
  272. RETURN
  273.  
  274. SCALEOBJECT:
  275.     parse arg objectidnew,factor
  276.  
  277.     txt_x = p2d(txtpos2.left,measure)
  278.     txt_y = p2d(txtpos2.top,measure)
  279.     txt_xx = p2d(txtpos2.right,measure)
  280.     txt_yy  = p2d(txtpos2.bottom,measure)
  281.     txtheight = txt_yy - txt_y
  282.     txtwidth  = txt_xx - txt_x
  283.  
  284.     newtxt_x = txt_x + txtwidth * factor
  285.     newtxt_y = txt_y + txtheight * factor
  286.     'EDITTEXTOBJ POSITION 'txt_x''measure' 'txt_y''measure' 'newtxt_x''measure' 'newtxt_y''measure' OBJECTID 'objectidnew
  287.     'GETTEXTOBJ POSITION txtpos2 OBJECTID 'textid
  288.  
  289. RETURN
  290.  
  291. SETBUSY:
  292.     parse arg value
  293.     'SETBUSYREQUESTER 'BusyReq' CURRENT 'value
  294.     'GETBUSYREQUESTER 'BusyReq
  295.     if result=1 then call CLEANUP(1)
  296. RETURN
  297.  
  298. CLEANUP:
  299.     'CLOSEBUSYREQUESTER 'BusyReq
  300.     'REFRESH ON'
  301.     'REFRESHWINDOW'
  302. EXIT
  303.  
  304. ReadTXTRotatorPrefs:
  305.     ok = Open('Prefs','PageStream3:Scripts/txtRotator.prefs','R')
  306.     if ok = 1 then do
  307.         say 'reading old prefs...'
  308.         textsize = ReadLN('Prefs')
  309.         charstyle = ReadLN('Prefs')
  310.         text = ReadLN('Prefs')
  311.         tposi = ReadLN('Prefs')
  312.         richtung = ReadLN('Prefs')
  313.         icf = ReadLN('Prefs')
  314.         xfaktor = ReadLN('Prefs')
  315.         Close('Prefs')
  316.         end
  317.     else do
  318.         say 'unable to read prefs -> default values'
  319.         textsize = '20pt'
  320.         charstyle = 'RoundText'
  321.         text = 'abcdefghijklmnopqrstuvwxyz0123456789 '
  322.         tposi = 0
  323.         richtung = 0
  324.         icf = 1
  325.         xfaktor = 1
  326.     end
  327. RETURN
  328.  
  329. WriteTXTRotatorPrefs:
  330.     ok = Open('Prefs','PageStream3:Scripts/txtRotator.prefs','W')
  331.     if ok = 1 then do
  332.         say 'writing prefs...'
  333.         WriteLN('Prefs',textsize)
  334.         WriteLN('Prefs',charstyle)
  335.         WriteLN('Prefs',text)
  336.         WriteLN('Prefs',tposi)
  337.         WriteLN('Prefs',richtung)
  338.         WriteLN('Prefs',icf)
  339.         WriteLN('Prefs',xfaktor)
  340.         Close('Prefs')
  341.         end
  342.     else do
  343.         say 'error writing prefs file "txtRotator.prefs"'
  344.     end
  345. RETURN
  346.  
  347.